-
Notifications
You must be signed in to change notification settings - Fork 100
Expose world helpers via workflow/api (v2) #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 60bb0b4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@artimath is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
f0c5331 to
ac7b480
Compare
ac7b480 to
60bb0b4
Compare
VaguelySerious
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing!
A lot of the documentation changes are great. We're not sure yet if we want to re-export all the functions top-level, instead, for now, I think we should document getWorld more and maybe make it available under /api too. Since users might eventually run into the world concept anyway, it's less confusing if there's a single way to interact with the API.
We'd be happy to merge this, if those changes are implemented, making this a mostly documentation-focused PR. If so, please also ensure DCO passes on your final commit
| Get workflow run status and metadata without waiting for completion. | ||
| </Card> | ||
| <Card href="/docs/api-reference/workflow-api/world" title="World helpers"> | ||
| Access the World singleton plus list/cancel APIs for runs, steps, events, and hooks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Access the World singleton plus list/cancel APIs for runs, steps, events, and hooks. | |
| Access the World API for programmatic access to run, step, event, and hook entities. |
|
|
||
| This works the same way in development and production—just make sure the usual `WORKFLOW_*` environment variables are present so the correct world implementation can be chosen. | ||
|
|
||
| ## Helper catalog |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might want to generate these from the interface, so they don't get outdated. For now, we could just link to the latest interface.ts file in the npm package?
|
|
||
| ### Programmatically list and control runs | ||
|
|
||
| If you want to show workflow progress directly in your product UI—or let trusted operators retry or cancel work—you can now call the same administrative helpers the CLI uses, straight from `workflow/api`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| If you want to show workflow progress directly in your product UI—or let trusted operators retry or cancel work—you can now call the same administrative helpers the CLI uses, straight from `workflow/api`. | |
| If you want to show workflow progress directly in your product UI, or let trusted operators retry or cancel runs, you can call `getWorld()` to access the full low-level API. See the [World helpers reference](/docs/api-reference/workflow-api/world) for a list of capabilities. |
| } | ||
| ``` | ||
|
|
||
| ### Programmatically list and control runs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ### Programmatically list and control runs | |
| ### Programmatically query and control runs |
| If you want to show workflow progress directly in your product UI—or let trusted operators retry or cancel work—you can now call the same administrative helpers the CLI uses, straight from `workflow/api`. | ||
|
|
||
| ```typescript lineNumbers | ||
| import { listRuns, cancelRun } from 'workflow/api'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example should be moved to /docs/api-reference/workflow-api/world and use getWorld instead
| /** | ||
| * Creates a workflow run using the configured World implementation. | ||
| */ | ||
| export function createRun( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should encourage users to use getWorld() directly instead, which makes the API more discoverable (i.e. what actions are available on a run? Just type world.runs. to find the list) and allows us to skip the duplication in this file
| type Event, | ||
| getHookByToken, | ||
| getRun, | ||
| getWorld, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It think it'd be fine to re-export getWorld and createWorld from src/api for discoverability (in addition to the export already on runtime)
|
|
||
| # Accessing the World singleton | ||
|
|
||
| > “Is there any public API to access the active default World? I'd like to be able to list active runs in my app, like I can via the CLI. I could store them myself, but if there is an API for this that works across testing and deployment, that'd be even better!” |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's skip this
PR: Expose world helpers via workflow/api (v2)
Summary
getWorldplus everyWorldhelper (runs/steps/events/hooks/queue/streams/start) directly fromworkflow/api, so application code can manage runs without reimplementingcreateWorld.setWorldto assert each helper delegates correctly and specifically exercises the “list runs then cancel” flow requested for Next.js/server usage.workflowpackage.Use Cases Addressed
listRuns,cancelRun, etc., without importing fromworkflow/runtime.getWorld()fromworkflow/api, matching CLI behavior across dev/test/prod setups.queue,createQueueHandler,writeToStream, etc.).setWorldin tests while still using the exported helpers, ensuring parity with production behavior.Implementation Details
packages/workflow/src/api.tsnow imports the relevant types from@workflow/world, re-exports them, and defines thin wrappers for everyWorldsubfunction plusstartWorld.@workflow/worldtopackages/workflow/package.jsondependencies and syncedpnpm-lock.yaml.packages/workflow/src/api.test.tswith full delegation coverage and the “list -> cancel” scenario.docs/content/docs/api-reference/workflow-api/world.mdx, updated the API index cards, and inserted a new “Programmatically list and control runs” section instarting-workflows.mdx..changeset/expose-world-helpers.mdso theworkflowpackage gets a patch bump.Verification
pnpm --filter workflow test -- src/api.test.tspnpm --filter workflow typecheckpnpm biome check packages/workflow/src/api.ts packages/workflow/src/api.test.tsNotes